package com.hongmeng.teamwork.controller;

import com.hongmeng.teamwork.constants.HttpHeadConstant;
import com.hongmeng.teamwork.domain.IDepartmentDomainService;
import com.hongmeng.teamwork.entity.base.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Log4j2
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Resource
    private IDepartmentDomainService departmentService;

    @GetMapping("/getDepartment")
    public Result<?> getDepartment(@RequestHeader(HttpHeadConstant.ACCESS_TOKEN) String accessToken,
                                    @RequestParam(name = "departmentId", defaultValue = "0", required = false) String departmentId) {
        try {
            return Result.ok(departmentService.getDepartmentByPid(accessToken, departmentId));
        } catch (Exception e) {
            log.error("DepartmentController.getDepartment.error: {}", e.getMessage(), e);
            return Result.ok("获取部门失败！");
        }
    }
}
